var app = getApp();
var collectDataKey = 'collectDataList';
Page({
  data:{
    userInfo: {},
    userOtherInfo: {
      age: 20,
      sex: 0,
      height: "170",
    },
    modalType: "",//"",name","icon","age","sex","height"
    cacheData: {
      name: "",
    },
    ageRange: [],
    showAgeSlider: false,
    arrowAnim:'',
    sexAnim: '',
    isSexViewShow: false,
  },
  
cancelClick:function(e)
{
     this.setData({
       modalType:"",
     })
},
confirmClick:function(e)
{
  this.data.userInfo.nickName = this.data.cacheData.name;
     this.setData({
       modalType:"",
       userInfo:this.data.userInfo,
     })
},
nameClick:function(e)
{
     this.setData({
       modalType:"name",
     }) 
},
nameInput:function(e)
{
    this.data.cacheData.name = e.detail.value;
    this.setData({
      cacheData: this.data.cacheData,
    })
},
iconClick:function(e)
{
      var that = this;
      wx.chooseImage({
        count: 1, // 默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res) {
          // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
          var tempFilePaths = res.tempFilePaths;
          that.data.userInfo.avatarUrl = tempFilePaths[0];
          that.setData({
            userInfo : that.data.userInfo,
          })
        }
      })
},
ageChange:function(e)
{
     this.data.userOtherInfo.age = this.data.ageRange[e.detail.value];
     this.setData({
       userOtherInfo :  this.data.userOtherInfo,
     })
},
heightChange:function(e)
{
     this.data.userOtherInfo.height = e.detail.value;
     var modalType =  (this.data.modalType == "height" ? "" : "height"); 
      this.setData({
          modalType :  modalType,
          userOtherInfo :  this.data.userOtherInfo,
        })
},
heightClick:function(e)
{
  var modalType =  (this.data.modalType == "height" ? "" : "height"); 
  this.setData({
       modalType :  modalType,
     })
},
sexClick:function(e)
{
  var that = this;
  var modalType =  (this.data.modalType == "sex" ? "" : "sex"); 

  var arrowAnim = wx.createAnimation({
    duration: 300,
    timingFunction: 'ease-out',
  });
  arrowAnim.rotate(modalType == "sex" ? 90 : 0).step();

  this.setData({
       modalType :  modalType,
       arrowAnim :  arrowAnim.export(),
     })
},
sexChange:function(e)
{
  this.data.userOtherInfo.sex = parseInt(e.detail.value);
  this.setData({
    userOtherInfo: this.data.userOtherInfo
  })
},
saveClick:function(e)
{
      wx.showActionSheet({
    itemList: ['确定'],
    success: function(res) {
      if (!res.cancel) {
           wx.showToast({
            title: '保存中',
            icon: "loading",
            duration: 2000
          });
      }
    }
  })
},
  onLoad:function(options)
  {
      // 初始化数据
      for (var i = 0; i < 60; i++)
      {
        this.data.ageRange[i] = 18 + i;
      }
      this.setData({
        ageRange : this.data.ageRange,
        userInfo: app.globalData.userInfo
      })
  },
  onReady:function(){
    // 页面渲染完成
    
  },
  onShow:function(){
    // 页面显示
    
  },
  onHide:function(){
    // 页面隐藏
    console.log('hide');
    return false;
  },
  onUnload:function(){
    // 页面关闭
       wx.showToast({
            title: '您没有保存',
            icon: null,
            duration: 2000
          });
  }
})